package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.model.Health;
import com.tj.jinzao.widgets.ChartQView;

import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 报告 Adapter
 * Created by wjy on 2019/1/10.
 */
public class HealthListItemAdapter extends BaseListAdapter<Health, HealthListItemAdapter.ViewHolder> {
    private ChartQView chartView;

    public HealthListItemAdapter(Context context, CopyOnWriteArrayList data, ChartQView chartView) {
        super(context, data);
        this.chartView=chartView;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_health_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Health health = mData.get(position);
         chartView.setInvidata();
        holder.score.setText(String.valueOf(health.getScores()));
        holder.health_status.setText(health.getScoreText());
        holder.date.setText(health.getReportTime());
        holder.lay_content.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if(onLongCickLinstener!=null){
                    onLongCickLinstener.onLongClick(Long.parseLong(String.valueOf(health.getId())));
                }
                return false;
            }
        });
    }
    public OnLongCickLinstener onLongCickLinstener;

    public void setOnLongCickLinstener(OnLongCickLinstener onLongCickLinstener) {
        this.onLongCickLinstener = onLongCickLinstener;
    }

    public interface OnLongCickLinstener{
        void onLongClick(Long id);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView score, date, health_status;
        FrameLayout lay_content;

        public ViewHolder(View itemView) {
            super(itemView);
            score = itemView.findViewById(R.id.tv_score);
            date = itemView.findViewById(R.id.tv_date);
            health_status = itemView.findViewById(R.id.tv_status);
            lay_content = itemView.findViewById(R.id.lay_content);
        }
    }


}
